<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
<style>
    table {
            width: 800px;
            margin: 100px auto;
            text-align: center;
            border-collapse: collapse;
            font-size: 14px;
        }
    thead tr {
            height: 30px;
            background-color: skyblue;
    }
    tbody tr {
            height: 30px;
        }

        tbody td {
            border-bottom: 1px solid #d7d7d7;
            font-size: 12px;
            color: blue;
        }

</style>
</head>
<body>
    <div class="wrap">
        <table>
            <thead>
                <tr>
                    <th>
                        <input type = "checkbox" id="j_cbAll">
                    </th>
                    <th>商品</th>
                    <th>价钱</th>
                </tr>
            </thead>
            <tbody id = "j_tb">
                <tr>
                    <td>
                        <input type = "checkbox">
                    </td>
                    <td>iPhone13</td>
                    <td>6000</td>
                </tr>
                <tr>
                    <td>
                        <input type = "checkbox">
                    </td>
                    <td>iPhone14</td>
                    <td>8000</td>
                </tr>
                <tr>
                    <td>
                        <input type = "checkbox">
                    </td>
                    <td>iPad</td>
                    <td>4000</td>
                </tr>
                <tr>
                    <td>
                        <input type = "checkbox">
                    </td>
                    <td>iPad Pro</td>
                    <td>5000</td>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
        var j_cbAll = document.getElementById('j_cbAll');
        var j_tbs = document.getElementById('j_tb').getElementsByTagName('input');
        //注册事件
        j_cbAll.onclick = function(){
            //this.checked 可以得到当前复选框的选中状态 如果是true 就是选中，如果是false 就是未选中
            for(var i = 0; i < j_tbs.length; i++){
                j_tbs[i].checked = this.checked;
            }
        }
        for(var i = 0; i < j_tbs.length; i++){
            j_tbs[i].onclick = function(){
                var flag = true;
                for(var i = 0; i < j_tbs.length; i++){
                    if(!j_tbs[i].checked){
                        flag = false;
                        break;
                    }
                }
                j_cbAll.checked = flag;
            }
        }
    </script>
    
</body>
</html>